<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Guava集合增强：让Java集合更强大</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            overflow-x: auto;
            position: relative;
        }
        
        .code-block::before {
            content: 'Java';
            position: absolute;
            top: 8px;
            right: 12px;
            font-size: 12px;
            color: #666;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .feature-card {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            transition: all 0.3s ease;
        }
        
        .feature-card:hover {
            transform: scale(1.05);
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .highlight-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 600;
        }
        
        .table-custom {
            border-collapse: separate;
            border-spacing: 0;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
        }
        
        .table-custom th {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-weight: 600;
            padding: 16px;
            text-align: left;
        }
        
        .table-custom td {
            background: white;
            padding: 16px;
            border-bottom: 1px solid #f0f0f0;
        }
        
        .table-custom tr:last-child td {
            border-bottom: none;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 8px;
            margin-top: -8px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-family: 'Noto Serif SC', serif;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">
                    Guava集合增强
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    让Java集合更强大、更优雅、更高效
                </p>
                <div class="flex justify-center space-x-6 text-lg">
                    <div class="flex items-center">
                        <i class="fas fa-shield-alt mr-2"></i>
                        <span>线程安全</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-rocket mr-2"></i>
                        <span>性能优化</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-code mr-2"></i>
                        <span>API优雅</span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12 max-w-6xl">
        <!-- Introduction -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8">
            <p class="text-lg leading-relaxed text-gray-700 mb-4">
                <span class="drop-cap">J</span>ava标准库里的集合类已经够用了，但你用过Guava的集合工具后就再也回不去了。Google工程师的良苦用心体现在每一个API设计上，用起来简直爽到飞起。今天就跟大家聊聊Guava集合增强那些让我爱不释手的特性。
            </p>
            <p class="text-lg leading-relaxed text-gray-700">
                Java标准库中的集合框架（java.util.*）提供了基础的数据结构实现，但在实际开发中，我们经常会遇到一些标准集合无法优雅解决的问题。Guava提供了一系列强大的集合增强功能，填补了这些空白。
            </p>
        </div>

        <!-- Guava Collections Overview -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">Guava集合体系概览</h2>
            <div class="mermaid">
                <script type="text/mermaid">
                graph TD
                    A[Guava集合增强] --> B[不可变集合]
                    A --> C[新集合类型]
                    A --> D[集合工具类]
                    
                    B --> B1[ImmutableList]
                    B --> B2[ImmutableSet]
                    B --> B3[ImmutableMap]
                    
                    C --> C1[Multimap]
                    C --> C2[BiMap]
                    C --> C3[Table]
                    C --> C4[RangeSet/Map]
                    
                    D --> D1[Collections2]
                    D --> D2[Iterables]
                    D --> D3[Lists/Sets/Maps]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#f5576c,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#4facfe,stroke:#fff,stroke-width:2px,color:#fff
                </script>
            </div>
        </div>

        <!-- Section 1: Immutable Collections -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">
                <i class="fas fa-lock mr-3 text-purple-600"></i>
                1. ImmutableCollection不可变集合的实现原理
            </h2>
            
            <h3 class="text-2xl font-semibold mb-4 mt-8">1.1 为什么需要不可变集合？</h3>
            
            <p class="text-lg leading-relaxed text-gray-700 mb-4">
                在日常开发中，我经常看到很多开发者写出这样的代码：
            </p>
            
            <div class="code-block p-6 mb-6">
                <pre><code>public static final List&lt;String&gt; CONSTANT_LIST = new ArrayList&lt;&gt;();
static {
    CONSTANT_LIST.add("item1");
    CONSTANT_LIST.add("item2");
    // ...
}</code></pre>
            </div>
            
            <div class="bg-red-50 border-l-4 border-red-500 p-4 mb-6">
                <p class="text-lg text-red-800">
                    <i class="fas fa-exclamation-triangle mr-2"></i>
                    看出问题了吗？虽然引用是final的，但集合内容却可以被修改！这会导致一些难以调试的并发问题。
                </p>
            </div>
            
            <p class="text-lg leading-relaxed text-gray-700 mb-6">
                Guava的不可变集合就是为了解决这个问题而设计的。它有以下几个关键优势：
            </p>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-8">
                <div class="feature-card rounded-lg p-6">
                    <i class="fas fa-shield-alt text-3xl mb-3"></i>
                    <h4 class="text-xl font-semibold mb-2">线程安全</h4>
                    <p>不需要同步，天然线程安全</p>
                </div>
                <div class="feature-card rounded-lg p-6">
                    <i class="fas fa-memory text-3xl mb-3"></i>
                    <h4 class="text-xl font-semibold mb-2">内存效率</h4>
                    <p>通常比可变集合更节省内存</p>
                </div>
                <div class="feature-card rounded-lg p-6">
                    <i class="fas fa-lock text-3xl mb-3"></i>
                    <h4 class="text-xl font-semibold mb-2">可被安全地用作常量</h4>
                    <p>不会被意外修改</p>
                </div>
                <div class="feature-card rounded-lg p-6">
                    <i class="fas fa-user-shield text-3xl mb-3"></i>
                    <h4 class="text-xl font-semibold mb-2">安全返回值</h4>
                    <p>可作为不可信代码的安全返回值</p>
                </div>
            </div>
            
            <h3 class="text-2xl font-semibold mb-4 mt-8">1.2 不可变集合的核心设计</h3>
            
            <div class="bg-purple-50 rounded-lg p-6 mb-6">
                <h4 class="text-xl font-semibold mb-3 text-purple-800">Guava的不可变集合家族</h4>
                <div class="grid grid-cols-2 md:grid-cols-3 gap-3">
                    <div class="bg-white rounded p-3 text-center shadow">
                        <i class="fas fa-list text-purple-600 text-2xl mb-2"></i>
                        <p>ImmutableList</p>
                    </div>
                    <div class="bg-white rounded p-3 text-center shadow">
                        <i class="fas fa-layer-group text-purple-600 text-2xl mb-2"></i>
                        <p>ImmutableSet</p>
                    </div>
                    <div class="bg-white rounded p-3 text-center shadow">
                        <i class="fas fa-map text-purple-600 text-2xl mb-2"></i>
                        <p>ImmutableMap</p>
                    </div>
                    <div class="bg-white rounded p-3 text-center shadow">
                        <i class="fas fa-project-diagram text-purple-600 text-2xl mb-2"></i>
                        <p>ImmutableMultimap</p>
                    </div>
                    <div class="bg-white rounded p-3 text-center shadow">
                        <i class="fas fa-sort text-purple-600 text-2xl mb-2"></i>
                        <p>ImmutableSortedSet</p>
                    </div>
                    <div class="bg-white rounded p-3 text-center shadow">
                        <i class="fas fa-sort-amount-up text-purple-600 text-2xl mb-2"></i>
                        <p>ImmutableSortedMap</p>
                    </div>
                </div>
            </div>
            
            <p class="text-lg leading-relaxed text-gray-700 mb-4">
                所有这些实现都遵循一个共同的设计模式：
            </p>
            
            <div class="code-block p-6 mb-6">
                <pre><code>// ImmutableX类的一般结构
public abstract class ImmutableX&lt;E&gt; extends AbstractX&lt;E&gt; {
    // 创建方法
    public static &lt;E&gt; ImmutableX&lt;E&gt; of() {...}
    public static &lt;E&gt; ImmutableX&lt;E&gt; of(E element) {...}
    public static &lt;E&gt; ImmutableX&lt;E&gt; of(E e1, E e2) {...}
    // ...
    
    // copy方法
    public static &lt;E&gt; ImmutableX&lt;E&gt; copy